var express = require('express');
let maileConfig = require("./maileConfig");
var router = express.Router();
const LocalStorage = require('node-localstorage').LocalStorage,
    localStorage = new LocalStorage('./scratch');

// 发送邮件的接口
router.get('/email', function (req, res, next) {

    let email = req.query.email;
    let code = createSixNum();
    console.log(code);

    var mail = {
        // 发件人
        from: '<ljc18182929@163.com>',
        // 主题
        subject: '验证码',//邮箱主题
        // 收件人
        to: email,//前台传过来的邮箱
        // 邮件内容，HTML格式
        text: '用' + code + '作为你的验证码'//发送验证码
    };
    maileConfig(mail)
    res.send({
        code: 200,
        msg: "发送成功",
        data: code
    })
    // 随机产生六位验证码
    function createSixNum() {
        var Num = "";
        for (var i = 0; i < 6; i++) {
            Num += Math.floor(Math.random() * 10);
        }
        return Num;
    }
});
module.exports = router;
